﻿#include<iostream>
using namespace std;
#include<assert.h>


class Date
{
public:
	bool CheckDate() const
	{
		if (_month < 1 || _month > 12
			|| _day < 1 || _day > GetMonthDay(_year, _month))
		{
			return false;
		}
		else
		{
			return true;
		}
	}
	Date(int year = 1900, int month = 1, int day = 1)
	{
		_year = year;
		_month = month;
		_day = day;

		if (!CheckDate())
		{
			cout << "非法日期:";
			Print();
		}
	}
	void Print() const
	{
		cout << _year << "/" << _month << "/" << _day << endl;
	}

	// Ĭinline
	int GetMonthDay(int year, int month) const
	{
		assert(month > 0 && month < 13);

		static int monthDayArray[13] = { -1, 31, 28, 31, 30, 31, 30,
31, 31, 30, 31, 30, 31 };

		if (month == 2 && ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)))
		{
			return 29;
		}

		return monthDayArray[month];
	}
	Date& operator-=(int day)
	{
		if (day < 0)
		{
			return *this += (-day);
		}

		_day -= day;
		while (_day <= 0)
		{
			--_month;
			if (_month == 0)
			{
				_month = 12;
				--_year;
			}

			_day += GetMonthDay(_year, _month);
		}

		return *this;
	}
	Date& operator+=(int day)
	{
		if (day < 0)
		{
			return *this -= (-day);
		}

		_day += day;
		while (_day > GetMonthDay(_year, _month))
		{
			_day -= GetMonthDay(_year, _month);
			++_month;
			if (_month == 13)
			{
				_year++;
				_month = 1;
			}
		}
		return *this;
	}

	// d1++;
	Date operator++(int)
	{
		Date tmp = *this;
		*this += 1;
		return tmp;
	}
	int GetYear()
	{
		return _year;
	}
	int GetMonth()
	{
		return _month;
	}
	int GetDay()
	{
		return _day;
	}
private:
	int _year;
	int _month;
	int _day;
};

int main()
{
	int n;
	cin >> n;
	int year = n / 10000;
	int month = n % 10000 / 100;
	int day = n % 100;
	Date d(year, month, day);
	int ans1 = 0, ans2 = 0;
	while (1)
	{
		d++;
		int arr[8] = { 0 };
		arr[0] = d.GetYear() / 1000;
		arr[1] = d.GetYear() / 100 % 10;
		arr[2] = d.GetYear() / 10 % 10;
		arr[3] = d.GetYear() % 10;
		arr[4] = d.GetMonth() / 10;
		arr[5] = d.GetMonth() % 10;
		arr[6] = d.GetDay() / 10;
		arr[7] = d.GetDay() % 10;
		int begin = 0;
		int end = 7;
		if (arr[begin] == arr[end])
		{
			while (begin < end)
			{
				if (arr[begin] != arr[end])
				{
					break;
				}
				++begin;
				--end;
			}
			if (begin > end)
			{
				if (ans2 == 0 && (arr[0] == arr[2] && arr[2] == arr[5] && arr[5] == arr[7]) && (arr[1] == arr[3] && arr[3] == arr[4] && arr[4] == arr[6]))
					ans2 = (d.GetYear() * 100 + d.GetMonth()) * 100 + d.GetDay();
				else
				{
					if (ans1 == 0)
						ans1 = (d.GetYear() * 100 + d.GetMonth()) * 100 + d.GetDay();
				}
			}
		}
		if (ans1 && ans2)
			break;
	}
	cout << ans1 << endl << ans2;
	return 0;
}